from flask import Flask
from flask import request

import os,sys
import commands
app = Flask(__name__)

@app.route('/cpisapp')
def cmd():
    if 'node' in request.args:
      NODE = request.args['node']
      a=os.popen('salt -N ' + NODE + ' cpisapp.cpisapp').read().replace('[1;32m','').replace('[31m','').replace('[0m','')
      b='<pre>%s</pre>' %a
      return b
    else:
      a=os.popen('salt \*  cpisapp.cpisapp').read().replace('[1;32m','').replace('[31m','').replace('[0m','')
      b='<pre>%s</pre>' %a
      return b

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=65534)

